/**
 * Created by Administrator on 2017/9/15 0015.
 */
import React from "react"
import { Transfer } from 'antd';



export default class TransferDom extends React.Component {
    state = {
        targetKeys:[],
        selectedKeys: [],
    }

    componentWillReceiveProps(props){
        this.setState({
            targetKeys:props.targetSource
        })

    }

    handleChange = (nextTargetKeys, direction, moveKeys) => {
        this.setState({ targetKeys: nextTargetKeys });

        if(direction ==="right"){
            this.props.onOkSet(moveKeys);
        }else{
            this.props.onCanCel(moveKeys)
        }

      /* console.log('targetKeys: ', this.state.targetKeys);
      console.log('direction: ', direction);*/
        /*console.log('moveKeys: ', moveKeys);*/
    }

    handleSelectChange = (sourceSelectedKeys, targetSelectedKeys) => {
        this.setState({ selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys] });

    }



    render() {
        const state = this.state;

        return (
            <Transfer
                dataSource={this.props.dataSource}
                titles={['未授权', '授权']}
                targetKeys={state.targetKeys}
                selectedKeys={state.selectedKeys}
                onChange={this.handleChange}
                onSelectChange={this.handleSelectChange}
             /*   onScroll={this.handleScroll}*/
                render={item => item.title}
            />
        );
    }
}